package vip.xiaonuo.biz.modular.lancerShopCart.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.biz.modular.pojo.domain.BizShopCartItem;
import vip.xiaonuo.biz.modular.pojo.dto.add.ShopCartItemAddDTO;
import vip.xiaonuo.biz.modular.pojo.dto.common.CommonDeleteDTO;
import vip.xiaonuo.biz.modular.pojo.dto.common.CommonDetailDTO;
import vip.xiaonuo.biz.modular.pojo.dto.edit.ShopCartItemEditDTO;
import vip.xiaonuo.biz.modular.pojo.dto.page.ShopCartItemPageDTO;
import vip.xiaonuo.biz.modular.lancerShopCart.service.BizShopCartItemService;
import vip.xiaonuo.common.pojo.CommonResult;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * 管理员购物车控制器
 *
 * @author admin
 * @date 2024/01/02
 */
@Api(tags = "购物车管理(管理端)")
@ApiSupport(author = "LANCER_TEAM", order = 1)
@Validated
@RestController
@RequestMapping
public class AdminShopCartItemController {

    @Autowired
    private BizShopCartItemService ShopCartItemService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("管理端购物车分页")
    @GetMapping("/biz/admin/shopCartItem/page")
    @SaCheckPermission("/biz/admin/shopCartItem/page")
    public CommonResult<Page<BizShopCartItem>> page(@Valid ShopCartItemPageDTO dto) {
        Page<BizShopCartItem> res = ShopCartItemService.pageLAdmin(dto);
        return CommonResult.data(res);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("管理端购物车详情查询")
    @GetMapping("/biz/admin/shopCartItem/detail")
    @SaCheckPermission("/biz/admin/shopCartItem/detail")
    
    public CommonResult<BizShopCartItem> detail(@Valid CommonDetailDTO dto) {
        BizShopCartItem res = ShopCartItemService.detail(dto);
        return CommonResult.data(res);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("管理端购物车新增")
    @PostMapping("/biz/admin/shopCartItem/add")
    @SaCheckPermission("/biz/admin/shopCartItem/add")
    
    public CommonResult<String> add(@Valid ShopCartItemAddDTO dto) {
        ShopCartItemService.add(dto);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("管理端购物车删除")
    @PostMapping("/biz/admin/shopCartItem/delete")
    @SaCheckPermission("/biz/admin/shopCartItem/delete")
    
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "删除id不能为空") List<CommonDeleteDTO> dto) {
        ShopCartItemService.delete(dto);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("管理端购物车选中的状态更改")
    @PostMapping("/biz/admin/shopCartItem/changeSelectStatus")
    @SaCheckPermission("/biz/admin/shopCartItem/changeSelectStatus")
    public CommonResult<String> changeSelectStatus(@Valid ShopCartItemEditDTO dto) {
        ShopCartItemService.edit(dto);
        return CommonResult.ok();
    }

}